package _q39

func majorityElement(nums []int) int {

	count, candidate := 0, nums[0]

	for _, num := range nums {
		if num == candidate {
			count++
		} else {
			count--
			if count == 0 {
				candidate = num
				count++
			}
		}
	}

	return candidate
}
